﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ecopsy.DataTier;
using System.Collections;
using AgencyEntityLib.Context;
using System.Xml;

namespace AgencyEntityLib.BaseEntity
{
     

    /// <summary>
    /// Предсталяет коллекцию   ContractSurface с заполненным SurfaceNumber
    /// 
    /// </summary>
    public class ContractSurface_DistrubeItemList : EntityList,ISqlSignature 
    {
        private const string _FillCommandName="SurfaceDistribution";
        public string SideID { get; set; }

        private  DateTime _DtStart = DateTime.Now;
        private  DateTime _DtEnd = DateTime.Now;
        public DateTime DtStart { get { return _DtStart; } set { _DtStart = value; } }
        public DateTime DtEnd { get { return _DtEnd; } set { _DtEnd = value; } }

        public string i_ID {get {return (i_ContractSurfaceItem==null? null:i_ContractSurfaceItem.ID) ;  }}
          
        public DateTime  i_DtStart {get {return (i_ContractSurfaceItem==null?AgencyLib_GlobalConstants.MinDate:i_ContractSurfaceItem.DtStart ) ; }}
        public DateTime i_DtFinish { get { return (i_ContractSurfaceItem == null ? AgencyLib_GlobalConstants.MinDate : i_ContractSurfaceItem.DtFinish); } }
     //   public int   i_Weight {get {return (i_ContractSurfaceItem == null?100: i_ContractSurfaceItem.Weight ); }}


        /// <summary>
        /// Тестируемый период 
        /// </summary>
        private ContractSurfaceItem _i_ContractSurfaceItem = null;
        public ContractSurfaceItem i_ContractSurfaceItem { get {return _i_ContractSurfaceItem; } set{_i_ContractSurfaceItem =value ;} }

        public override void Load()
        {
            base.Load();
        }
        
        

        public override void ReadXml(XmlNode Node)
        {
          
            foreach (System.Xml.XmlNode nd in Node.ChildNodes)
            {
                if (nd.ChildNodes.Count == 0)// без узла xml
                {
                    ContractSurfaceItem i = new ContractSurfaceItem();
                    i.ID=nd.Attributes["ID"].Value;
                    i.SurfaceNumber = Convert.ToInt16(nd.Attributes["SurfNumber"].Value);
                    Add(i);
                    continue;
                }



                XmlNode ch = nd.ChildNodes[0].ChildNodes [0];
                string sAssmblyName = (ItemAssemblyName.Length == 0 ? ch.Attributes[SerilizeContext.AssemblyPref].Value : ItemAssemblyName);
                string sItemAssemblyType = (ItemAssemblyType.Length == 0 ? ch.Attributes[SerilizeContext.TypePref].Value : ItemAssemblyType);
                string sSurfNumber = nd.Attributes["SurfNumber"].Value;

                //Type Tr = ReflectionItem.MyGetType(sAssmblyName, sItemAssemblyType);

                Type Tr = ReflectionItem.MyGetType(sAssmblyName, sItemAssemblyType);
                ISerializableItem obj = (ISerializableItem)Activator.CreateInstance(Tr);                
                ((ContractSurfaceItem)obj).SurfaceNumber = Convert.ToInt16(sSurfNumber);
                obj.ReadXml(ch);
                Add(obj as EntitySingle);
            }
        }

         

        #region ISqlSignature Members

        public string SaveProcedure
        {
            get { throw new NotImplementedException(); }
        }

        public string DeleteProcedure
        {
            get { throw new NotImplementedException(); }
        }

        public string LoadProcedure
        {
            get { return "ContractSurface_DistrubeItemList_Load"; }
        }

        #endregion
    }


    


}
